package com.tarena.lbs.business.service.impl;

import org.springframework.data.geo.Point;
import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class RedisGeoService {
    private final RedisTemplate<String, Object> redisTemplate;

    public RedisGeoService(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }
    public void addStoreLocation(String key, double longitude, double latitude, String member) {
        Point point = new Point(longitude, latitude);
        RedisGeoCommands.GeoLocation<String> location = new RedisGeoCommands.GeoLocation<>(member, point);
        // 将 GeoLocation 转换为 Map
        Map<Object, Point> locationMap = new HashMap<>();
        locationMap.put(member, point);
        // 使用 geoAdd 方法
        redisTemplate.opsForGeo().add(key, locationMap);
    }
}
